﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Web.UI.WebControls;
using SharedLibraries.Constants;
using ThangNM_LIB.EO;
using ThangNM_LIB.FUNC;

namespace ThangNM.UserControl
{
    public partial class LogsUC : System.Web.UI.UserControl
    {
        //public List<LogEO> lstLogEO
        //{
        //    get { return (List<LogEO>)ViewState["lstLogEO"]; }
        //    set { ViewState["lstLogEO"] = value; }
        //}

        //protected void Page_Load(object sender, EventArgs e)
        //{
        //    MsgUC1.setClearMsg();
        //    if (!IsPostBack)
        //    {
        //        BindData_DropDownList();
        //    }
        //}

        //protected void BindData_Grid()
        //{
        //    grvError.DataSource = lstLogEO;
        //    grvError.DataBind();
        //    lblTotal.Text = String.Format("Tổng số bản ghi: {0}", lstLogEO.Count);
        //}

        //private void BindData_DropDownList()
        //{
        //    try
        //    {
        //        String strPath = System.Configuration.ConfigurationManager.AppSettings["RawUrl_RootPath"] + "Logs\\";
        //        ddlFileError.DataSource = Folder_File.getListFileInFolder(strPath);
        //        ddlFileError.DataTextField = "Value";
        //        ddlFileError.DataValueField = "Key";
        //        ddlFileError.DataBind();
        //        getData();
        //    }
        //    catch (Exception ex)
        //    {
        //        MsgUC1.setNotifications(ConstEx.FunctionSetMsg.ERROR, ex.Message, ex.ToString());
        //    }
        //}

        //protected void getData()
        //{
        //    try
        //    {
        //        String sPath = ddlFileError.SelectedValue;
        //        String sContent = "";
        //        lstLogEO = (new Logs()).ReadLog_From_File(sPath, ref sContent);
        //        txtContent.Text = sContent;
        //        BindData_Grid();
        //    }
        //    catch (Exception ex)
        //    {
        //        MsgUC1.setNotifications(ConstEx.FunctionSetMsg.ERROR, ex.Message, ex.ToString());
        //    }
        //}

        //protected void btnLoad_Click(object sender, EventArgs e)
        //{
        //    getData();
        //}

        //protected void btnClearItem_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        if (!String.IsNullOrEmpty(ddlFileError.SelectedValue))
        //        {
        //            lstLogEO.Clear();
        //            txtContent.Text = "";
        //            File.Delete(ddlFileError.SelectedValue);
        //            BindData_Grid();
        //            BindData_DropDownList();
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        MsgUC1.setNotifications(ConstEx.FunctionSetMsg.ERROR, ex.Message, ex.ToString());
        //    }
        //}

        //protected void btnMoveItem_Click(object sender, EventArgs e)
        //{
        //    String sTemp = (new Logs()).WriteLog_File_To_DB(false, ddlFileError.SelectedValue);
        //    if (String.IsNullOrEmpty(sTemp))
        //        MsgUC1.setNotifications(ConstEx.FunctionSetMsg.SUCCESS, String.Format("Chuyển file log [{0}] vào DB thành công.", ddlFileError.SelectedValue));
        //    else
        //        MsgUC1.setNotifications(ConstEx.FunctionSetMsg.WARNING, String.Format("Chuyển file log [{0}] vào DB thất bại.<BR />{1}", ddlFileError.SelectedValue, sTemp));
        //}

        //protected void btnMoveAll_Click(object sender, EventArgs e)
        //{
        //    String sTemp = (new Logs()).WriteLog_File_To_DB(false, null);
        //    if (String.IsNullOrEmpty(sTemp))
        //        MsgUC1.setNotifications(ConstEx.FunctionSetMsg.SUCCESS, String.Format("Chuyển tất cả các file vào DB thành công."));
        //    else
        //        MsgUC1.setNotifications(ConstEx.FunctionSetMsg.WARNING, String.Format("Chuyển tất cả các file vào DB thất bại.<BR />{0}", sTemp));
        //}

        //protected void grvError_PageIndexChanging(object sender, GridViewPageEventArgs e)
        //{
        //    grvError.PageIndex = e.NewPageIndex;
        //    BindData_Grid();
        //}

        //protected void ddlFileError_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    getData();
        //}
    }
}